package com.yunfeng.aolin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yunfeng.aolin.dao.PurchaseGoodsDAO;
import com.yunfeng.aolin.entity.PurchaseGoods;
import com.yunfeng.aolin.service.PurchaseGoodsService;
import com.yunfeng.common.util.Page;
import com.yunfeng.common.util.PageUtils;

@Service
@Transactional
public class PurchaseGoodsServiceImpl implements PurchaseGoodsService {

	@Autowired
	private PurchaseGoodsDAO purchaseGoodsDAO;

	/**
	 * @param id
	 * @return
	 * @see com.yunfeng.aolin.service.PurchaseGoodsService#get(java.lang.Long)
	 */
	@Override
	public PurchaseGoods get(Long id) {
		return purchaseGoodsDAO.findOne(id);
	}

	/**
	 * @param purchaseGoods
	 * @see com.yunfeng.aolin.service.PurchaseGoodsService#saveOrUpdate(com.yunfeng.aolin.entity.PurchaseGoods)
	 */
	@Override
	public void saveOrUpdate(PurchaseGoods purchaseGoods) {
		purchaseGoodsDAO.save(purchaseGoods);
	}

	/**
	 * @param id
	 * @see com.yunfeng.aolin.service.PurchaseGoodsService#delete(java.lang.Long)
	 */
	@Override
	public void delete(Long id) {
		purchaseGoodsDAO.delete(id);
	}

	@Override
	public List<PurchaseGoods> findAll() {
		// TODO Auto-generated method stub
		return purchaseGoodsDAO.findAll();
	}

	/**
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.PurchaseGoodsService#findAll(com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<PurchaseGoods> findAll(Page page) {
		org.springframework.data.domain.Page<PurchaseGoods> springDataPage = purchaseGoodsDAO
				.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * @param page
	 * @param pinming
	 * @return
	 * @see com.yunfeng.aolin.service.PurchaseGoodsService#findByPinming(com.ketayao.ketacustom.util.dwz.Page,
	 *      java.lang.String)
	 */
	@Override
	public List<PurchaseGoods> findByPinming(Page page, String pinming) {
		org.springframework.data.domain.Page<PurchaseGoods> springDataPage = purchaseGoodsDAO
				.findByPinmingContaining(pinming,
						PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * 
	 * @param specification
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.PurchaseGoodsService#findByExample(org.springframework.data.jpa.domain.Specification,
	 *      com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<PurchaseGoods> findByExample(
			Specification<PurchaseGoods> specification, Page page) {
		org.springframework.data.domain.Page<PurchaseGoods> springDataPage = purchaseGoodsDAO
				.findAll(specification, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}
}
